
package com.zidian.leader.common.adapter;


import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.zidian.leader.R;
import com.zidian.leader.common.listener.OnAdvancedRecycleViewItemLongClickListener;
import com.zidian.leader.common.listener.OnAdvancedRecyclerViewItemListener;
import com.zidian.leader.common.listener.OnAdvancedRecyclerViewLoadMoreListener;

import butterknife.ButterKnife;


/**
 * 自定义 AdvancedRecyclerView 通用的 BarChartViewHolder
 * Created by Zuo Ji on 2015/7/28.
 */
public class AdvancedRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {

    private OnAdvancedRecyclerViewItemListener onItemClickListener;

    private OnAdvancedRecyclerViewLoadMoreListener onLoadMoreListener;

    private OnAdvancedRecycleViewItemLongClickListener onItemLongClickListener;

    public int position;

    public TextView loadMoreTextView;

    public ProgressBar loadMoreProgressBar;

    public AdvancedRecyclerViewHolder(View itemView, int viewType,
                                      OnAdvancedRecyclerViewItemListener onItemClickListener,
                                      OnAdvancedRecyclerViewLoadMoreListener onLoadMoreListener,
                                      OnAdvancedRecycleViewItemLongClickListener onItemLongClickListener) {
        super(itemView);

        this.onItemClickListener = onItemClickListener;
        this.onLoadMoreListener = onLoadMoreListener;
        this.onItemLongClickListener = onItemLongClickListener;
        itemView.setOnClickListener(this);
        itemView.setOnLongClickListener(this);
        if (viewType == AdvancedRecyclerViewAdapter.TYPE_FOOTER) {
            loadMoreTextView = ButterKnife.findById(itemView, R.id.recyclerViewLoadMoreTextView);
            loadMoreProgressBar = ButterKnife.findById(itemView, R.id.recyclerViewLoadMoreProgressBar);
        }
    }


    @Override
    public void onClick(View v) {
        if (getItemViewType() == AdvancedRecyclerViewAdapter.TYPE_ITEM && onItemClickListener != null) { // item 点击事件
            onItemClickListener.onItemClick(position, v);
        } else if (onLoadMoreListener != null) { // 加载更多的点击事件
            onLoadMoreListener.onLoadMore();
        }
    }

    @Override
    public boolean onLongClick(View v) {
        if (getItemViewType() == AdvancedRecyclerViewAdapter.TYPE_ITEM && onItemLongClickListener != null) { // 普通视图并且非空判断 长按事件
            onItemLongClickListener.onItemLongClick(position, v);
        }
        return true;
    }
}
